package com.ag.oa.core.service.impl;

import com.ag.oa.core.dao.INewsDao;
import com.ag.oa.core.entity.vo.NewsVO;
import com.ag.oa.core.service.INewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("newsServiceImpl")
public class NewsServiceImpl implements INewsService {

    @Autowired
    private INewsDao newsDao;

    @Override
    public void saveNewsByAdmin(Integer id, String title, String contentURL, String coverURL, String content, Integer queue) {

        if (id==null) {
            newsDao.saveAddByAdmin(title, contentURL, coverURL, content, queue);
        } else {
            newsDao.updateByAdmin(id, title, contentURL, coverURL, content, queue);
        }
    }

    @Override
    public List<NewsVO> getForNewsDataList(Integer topNum, Integer page, Integer pageSize) {

        if (page==null) {
            page = 0;
        }
        if (pageSize==null) {
            pageSize = 20;
        }
        return newsDao.getNewsList(topNum, page * pageSize, pageSize);
    }

    @Override
    public NewsVO getNewsInfoById(Integer id) {

        return newsDao.getById(id);
    }

    @Override
    public void delNewsById(Integer id) {

        newsDao.delById(id);
    }

    @Override
    public int getTotalRecordsCount() {

        return newsDao.getTotalCount();
    }

    @Override
    public void updateSticky(Integer sticky, Integer id) {
        newsDao.updateSticky(sticky, id);
    }


}
